//
//  BannerCollectionReusableView.m
//  GOGOTravel
//
//  Created by dllo on 16/1/30.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "BannerCollectionReusableView.h"

@interface BannerCollectionReusableView ()

@property (nonatomic, retain) NSMutableArray *dataArr;


@end

@implementation BannerCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self handelData];
        
        
    }
    return self;
}

/** 实现协议方法 */

//创建轮播图
- (void)initBanner{
    
    NSMutableArray *arr = [NSMutableArray array];
    
    for (DesBanner *model in _dataArr) {
        NSString *strr = model.image_url;
        [arr addObject:strr];
    }
    
    DCPicScrollView *dc = [DCPicScrollView picScrollViewWithFrame:CGRectMake(0, 0, self.frame.size.width, 200) WithImageUrls:arr];
    
    dc.placeImage = [UIImage imageNamed:PLACE_HLODER];
    dc.AutoScrollDelay = 2;
    
    [self addSubview:dc];
    
    [[DCWebImageManager shareManager] setDownloadImageRepeatCount:1];
    [[DCWebImageManager shareManager] setDownLoadImageError:^(NSError *error, NSString *string) {
        NSLog(@"%@", error);
    }];
    //点击方法
    [dc setImageViewDidTapAtIndex:^(NSInteger index) {
        DesBanner *model = _dataArr[index];
        [self.delegate JumeToVc:model.html_url];
        
        
        
        NSLog(@"%ld", (long)index);
    }];
    
    
}


/**<  数据处理 */
- (void)handelData{
    
    [AFNetWorkingHandle GETRequestWithURLString:@"http://api.breadtrip.com/destination/v3/?last_modified_since=0" completionWithSuccess:^(id result) {
        
        NSArray *arr = result[@"banners"];
        
        self.dataArr = [DesBanner ModelHandleWithArray:arr];
        
        NSLog(@"%@", _dataArr);
        [self initBanner];
    } withFailure:^(id error) {
        NSLog(@"%@", error);
    }];

    
    
    
    
    
}




- (void)dealloc{
    [_dataArr release];
    [super dealloc];
}
@end
